#include "AxisEntity.h"

namespace egg{

    AxisEntity::AxisEntity(uint32 vertNum){
        mShader=gShaderLib.getShader("axis");
        mGeometry=GeometryPtr(new Geometry());
        mColorBuf=VertexBufferPtr(new VertexBuffer(VA_COLOR0,vertNum,BU_STATIC,0));
        mPositionBuf=VertexBufferPtr(new VertexBuffer(VA_POSITION,vertNum,BU_STATIC,0));
        mGeometry->attachVertexBuffer("position",mPositionBuf);
        mGeometry->attachVertexBuffer("color",mColorBuf);
    }

    void AxisEntity::addAxis(const vec3& p,const vec3& x,const vec3& y,const vec3& z){
        const float colors[24]={
            1,0,0,1,1,0,0,1,
            0,1,0,1,0,1,0,1,
            0,0,1,1,0,0,1,1};
        float xAxis[6]={p.x,p.y,p.z,p.x+x.x,p.y+x.y,p.z+x.z};
        float yAxis[6]={p.x,p.y,p.z,p.x+y.x,p.y+y.y,p.z+z.z};
        float zAxis[6]={p.x,p.y,p.z,p.x+z.x,p.y+y.y,p.z+z.z};
        mPositionBuf->append(&xAxis,2);
        mPositionBuf->append(&yAxis,2);
        mPositionBuf->append(&zAxis,2);
        mColorBuf->append(colors,6);
    }

}